class WorkspaceNote <  ActiveRecord::Base
  establish_connection :discourse_test
  set_table_name 'workspaces_notes'
  
  #ruby script\runner WorkspaceNote.migrate
  def self.migrate
    wrkspn = WorkspaceNote.find_by_sql(["SELECT w.title, w.description, n.title AS notes_title, n.text FROM workspaces w, workspaces_notes wn, notes n WHERE n.note_id = wn.note_id AND w.workspace_id = wn.workspace_id"])
    
    wrkspn.each do |wn|
      w = Workspace.find_by_title(wn.title)
      w = Workspace.create(:title => wn.title, :content => "#{wn.description}")if w.nil?
      n = Note.find_by_title(wn.notes_title)
      n = Note.create(:title => wn.notes_title, :content => "#{wn.text}") if n.nil?
      Relation.create("object_id"=>w.id, "subject_id"=>n.id)
    end
  end
end
